import reqwest from 'reqwest'

import * as Api from '../../api/Api'

export const REQUEST_ARTICLE = 'REQUEST_ARTICLE'
export const RECEIVE_ARTICLE = 'RECEIVE_ARTICLE'


export function fetchArticle(id) {
	return (dispatch, getSate) => {
		dispatch({
			type: 'REQUEST_ARTICLE'
		})
		reqwest({
			url: Api.getArticle,
			method: 'post',
			data: {
				version_id: '1.1.0',
				info_id: id,
				channel_id: 1
			},
			success: function(data) {
				console.log(JSON.parse(data))
				dispatch({
					type: 'RECEIVE_ARTICLE',
					article: JSON.parse(data).databody
				})
				//window.location.href = JSON.parse(data).databody.content_url
			}
		})
	}
}